package kr.co.doriclassic.powerjava.chapter11;
class Fly{
	String name;

	@Override
	public String toString() {
		return String.format("fly [name=%s]", name);
	}
	
}
public class Car {
	private static Car car;
	int speed;
	int gear;
	public String color;
	public void speedUp(int increment){
		speed += increment;
	}
	public void speedDown(int increment){
		speed -= increment;
	}
	@Override
	public String toString() {
		return String.format("Object[%s]->Car [speed=%s, gear=%s, color=%s]", super.toString(), speed, gear,
				color);
	}
	
	public static void main(String[] args) {
		Car car = new Car();
		car.gear = 1;
		car.color = "red";
		car.speedUp(60);
		//System.out.println(car);
		
//		Object obj = car;//부모는 자식을 받을 수 있지만
//		System.out.println(obj.toString());
	
		//Car car2 = new Object();//자식은 부모를 가질 수 없다.
		Car car2 = new Car();
		car2.color="blue";
		car2.gear=2;
		car2.speedUp(80);
		
		Fly fly = new Fly();
		fly.name = "fly01";
		Fly fly2 = new Fly();
		fly2.name = "fly02";
		
		Car[] arrCar = new Car[2];
		Fly[] arrFly = new Fly[2];
		
		arrCar[0]=car;
		arrCar[1]=car2;
		
		arrFly[0]=fly;
		arrFly[1]=fly2;
				
		prnArr(arrCar);
		prnArr(arrFly);
	
		//
		Object[] arrObj = new Object[4];
		arrObj[0] = car;
		arrObj[1] = car2;
		arrObj[2] = fly;
		arrObj[3] = fly2;
		//((Car)arrObj[0]).gear=39;
		prnArr(arrObj);
	}
	
	private static void prnArr(Object[] arrObj) {
		for (int i = 0; i < arrObj.length; i++) {
			System.out.println(arrObj[i]);
		}
		System.out.println();
	}
	private static void prnArr(Fly[] arrFly) {
		for (int i = 0; i < arrFly.length; i++) {
			System.out.println(arrFly[i]);
		}
		System.out.println();
	}
	private static void prnArr(Car[] arrCar) {
		for (int i = 0; i < arrCar.length; i++) {
			System.out.println(arrCar[i]);
		}
		System.out.println();
	}
	
}
